package com.ruoyi.points.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.points.domain.Point;
import com.ruoyi.points.service.IPointService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 位移监测点Controller
 * 
 * @author ruoyi
 * @date 2024-04-19
 */
@Controller
@RequestMapping("/points/point")
public class PointController extends BaseController
{
    private String prefix = "points/point";

    @Autowired
    private IPointService pointService;

    @RequiresPermissions("points:point:view")
    @GetMapping()
    public String point()
    {
        return prefix + "/point";
    }

    /**
     * 查询位移监测点列表
     */
    @RequiresPermissions("points:point:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Point point)
    {
        startPage();
        List<Point> list = pointService.selectPointList(point);
        return getDataTable(list);
    }

    /**
     * 导出位移监测点列表
     */
    @RequiresPermissions("points:point:export")
    @Log(title = "位移监测点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Point point)
    {
        List<Point> list = pointService.selectPointList(point);
        ExcelUtil<Point> util = new ExcelUtil<Point>(Point.class);
        return util.exportExcel(list, "位移监测点数据");
    }

    /**
     * 新增位移监测点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存位移监测点
     */
    @RequiresPermissions("points:point:add")
    @Log(title = "位移监测点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Point point)
    {
        return toAjax(pointService.insertPoint(point));
    }

    /**
     * 修改位移监测点
     */
    @RequiresPermissions("points:point:edit")
    @GetMapping("/edit/{pointId}")
    public String edit(@PathVariable("pointId") Long pointId, ModelMap mmap)
    {
        Point point = pointService.selectPointByPointId(pointId);
        mmap.put("point", point);
        return prefix + "/edit";
    }

    /**
     * 修改保存位移监测点
     */
    @RequiresPermissions("points:point:edit")
    @Log(title = "位移监测点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Point point)
    {
        return toAjax(pointService.updatePoint(point));
    }

    /**
     * 删除位移监测点
     */
    @RequiresPermissions("points:point:remove")
    @Log(title = "位移监测点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pointService.deletePointByPointIds(ids));
    }
}
